package guijavacommander.tasks;

import guijavacommander.tasks.Task;
import guijavacommander.tasks.ProgressListener;

import javax.swing.*;
import java.awt.*;

/**
 * User: Deady
 * Date: 17.07.2009
 * Time: 10:48:45
 */
public class FilesThreadDialog extends ThreadDialog {

    JProgressBar bar;
    JProgressBar subBar;
    FilesTask task;
    JLabel desc;



    public FilesThreadDialog(Frame owner, FilesTask task) throws HeadlessException {
        super(owner, task);
    }

    protected void initGui(final Task task) {
        this.task = (FilesTask) task;

        bar = new JProgressBar(this.task.getMin(), this.task.getMax());
        bar.setStringPainted(true);
        subBar = new JProgressBar(this.task.getSubMin(), this.task.getSubMax());
        subBar.setStringPainted(true);
        desc = new JLabel();

        JPanel panel = new JPanel();
        panel.add(bar);
        getContentPane().add(panel, BorderLayout.SOUTH);
        this.task.addProgressListener(new ProgressListener() {
            public void progressUpdated(int currentProgress) {
                bar.setValue(currentProgress);
                subBar.setMaximum(FilesThreadDialog.this.task.getSubMax());
            }
        });


        this.task.addSubProgressListener(new ProgressListener() {
            public void progressUpdated(int currentProgress) {
                subBar.setValue(currentProgress);
            }
        });

        this.task.addDescriptionListener(new DescriptionListener() {
            public void descriptionUpdated(String description) {
                desc.setText(description);
            }
        });


        desc.setText(task.getDescription());

        JPanel rootPanel = new JPanel();
        rootPanel.setLayout(new BoxLayout(rootPanel, BoxLayout.Y_AXIS));
        rootPanel.add(desc);
        rootPanel.add(Box.createVerticalStrut(5));
        rootPanel.add(bar);
        rootPanel.add(Box.createVerticalStrut(5));
        rootPanel.add(subBar);

        setSize(450, 100);
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(rootPanel, BorderLayout.CENTER);

    }

}
